<include file="Public:header" />
<style>
body { background: #f5f5f5; }
.list-group { margin-bottom: 5px; }
.pages { text-align: center; }
a { color: #333; }
.panel { background: #fff; }
.headernav a { font-size: 1.3em; color: #fff; }
.media { padding-left: 5px; padding-bottom: 10px; }
</style>
<div style="background:#333; height:40px; line-height:40px;" class="headernav">
    <a href="javascript:history.go(-1);" style="height:40px; width:40px; display:block; float:left; text-align:center;">
        <i class="glyphicon glyphicon-menu-left"></i>
    </a>
    <a href="__APP__/" style="height:40px; width:40px; display:block; float:right; text-align:center;">
        <i class="glyphicon glyphicon-home"></i>
    </a>
</div>
<div class="mains">
    <div class="panel panel-info" style=" margin: 5px 5px 0px 5px ;">
        <div class="panel-heading">
            <i class="glyphicon glyphicon-credit-card"></i>&nbsp;
            <span style="" id="payPro">
            <empty name="html">请选择一种支付方式
                <else/>
                正在处理，请稍等……</empty>
            </span>
        </div>
        <?php $mykey = 0; foreach($productList as $key => $vo){?>
        <?php if($mykey > 0){?>
        <div class="line_" style="height:1px; margin:0 5px; background:#ddd;">
        </div>
        <?php }?>
        <div class="media" style="position:relative;" id="cart_<?php echo $vo['id'];?>">
            <div class="media-left">
                <a href="##" style="width:80px; height:80px; display:block;">
                    <img width="80" height="80" class="media-object" src="<?php echo getThumbPath($vo['img_url']);?>" data-holder-rendered="true" style="width: 80px; height: 80px;">
                </a>
            </div>
            <div class="media-body">
                <h4 class="media-heading"><?php echo $vo['title'];?></h4>
                <p>
                    <?php if(!empty($vo['attrmes'][0])){?>
                    <span style="color:rgba(203,189,190,1.00)">规格:&nbsp;&nbsp;</span>
                    <?php foreach($vo['attrmes'] as $vos){?>
                    <span><?php echo $vos ?>&nbsp;&nbsp;</span>
                    <?php }?>
                    <?php }?>
                </p>
                <div class="row" style="line-height:30px;">
                    <div class="col-xs-6">
                        <div class="input-group input-group-sm">
                            <span class="input-group-btn">
                            <button class="btn btn-default sub_" type="button">-</button>
                            </span>
                            <input class="form-control cartNum" style="text-align:center;" goods_id="<?php echo $cartdata[$key][0];?>" goods_title="<?php echo $cartdata[$key][1];?>" goods_price="<?php echo $cartdata[$key][3];?>" goods_attr="<?php echo $cartdata[$key][4];?>" type="text" name="" value="<?php echo $vo['num'];?>">
                            <span class="input-group-btn">
                            <button class="btn btn-default add_" type="button">+</button>
                            </span>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        &times;&nbsp;<span style="color:#f00;">¥<?php echo $vo['price'];?></span>
                    </div>
                </div>
            </div>
            <a href="javascript:void(0);" style="position:absolute; bottom:5px; font-size:1.5em; right:10px;" onClick="deletecart('<?php echo $cartdata[$key][0];?>',this);">
                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
            </a>
        </div>
        <?php $mykey++; }?>
        <div class="panel-body" style="text-align:center;">
            <h4>应付金额</h4>
            <p>
                <span style="font-size:3em; color:#f00; font-family:Arial">¥{$orderinfo.total}</span>
            </p>
            <h4>订单号：<span style="font-family:Arial;">{$orderinfo.ordernumber}</span></h4>
            <empty name="html">
                <form action="{:U('Payment/index', array('id' => $orderinfo['id']))}" method="post" id="payform">
                    <input name="pay_id" id="pay_id" value="{$paymentList.0.id}" type="hidden">
                    <div class="list-group">
                        <volist name="paymentList" id="vo">
                            <a href="##" style="border-radius:0; margin:8px;" onClick="setPayType({$vo.id},this);" class="list-group-item  <eq name="key" value="0">
                                active
                                </eq>
                                ">
                                
                                {$vo.title}
                            </a>
                        </volist>
                    </div>
                </form>
<script>
function setPayType(id,e){
	$('#pay_id').val(id); $(e).parent().find('.list-group-item').removeClass('active');$(e).addClass('active');
}
</script>
            </empty>
            {$html}
        </div>
    </div>
    <empty name="html">
        <button style="margin:0 auto; margin-top:20px; width:95%; display:block;" type="button" onClick="document.getElementById('payform').submit();" class="btn btn-success btn-lg">确认</button>
    </empty>
    <!-- 支付成功引导用户出去 -->
    <div class="row" style="display:none;" id="payend">
        <div class="col-xs-6 col-sm-6">
            <a style="display:block; margin:10px;" href="__APP__/" class="btn btn-warning btn-lg">
                <i class="fa fa-home"></i> 返回首页
            </a>
        </div>
        <div class="col-xs-6 col-sm-6">
            <a style="display:block; margin:10px;" href="{:U('Member/Order/index')}" class="btn btn-default btn-lg">
                <i class="fa fa-list-alt"></i> 查看订单
            </a>
        </div>
    </div>
    <!-- -->
    
</div>
<style>
	 .panel-body button{display:block; width:100%;}
	 </style>
<script>
function paySuccess(){
	$('#payPro').html('支付成功！');
	$('#payend').show();
}
function deletecart(id,e){
    if(!confirm('您确定要删除吗？')){
		return false;
	}
	$.post('<?php echo U('Cart/delete');?>',{'id':id,'cart':1},function(data){
		if(data.status == 1){
			$(e).parent().prev('.line_').remove();
			$(e).parent().remove();
			
			$('#_total').html(data.total);
		}
	},'json');
}


//更新购物车
$('.add_').click(function(e) {
	var val = $(this).parent().prev('input').eq(0).val()*1;
	$(this).parent().prev('input').eq(0).val(val + 1);
	changeNum($(this).parent().prev('input').eq(0));
});
$('.sub_').click(function(e) {
    var val = $(this).parent().next('input').eq(0).val()*1;
	if(val > 1){
		$(this).parent().next('input').eq(0).val(val - 1);
	}
    changeNum($(this).parent().next('input').eq(0));
});


function changeNum(e){
	$.ajax({
			url:'<?php echo U('Cart/update');?>',
			data:"id="+$(e).attr('goods_id')+"&title="+$(e).attr('goods_title')+"&price="+$(e).attr('goods_price')+"&total="+$(e).val()+"&attr="+$(e).attr('goods_attr')+'&cart=1',
			type:'POST',
			dataType:"html",
			success: function(data){
				if(data != ''){
				    $('#_total').html(data);
				}
			}
		});
}



//更新购物车
$(".cartNum").each(function(index, element) {
	$(this).change(function(e) {
		if($(this).val() < 1){
		$(this).val(1);
	}
        
		
		
		changeNum(element);
		
    });
    
});



</script>
<include file="Public:footer" />